package com.example.myyiyanmengjava.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.mvplibrary.ui.fragment.BaseMvpFragment;
import com.example.myyiyanmengjava.HomeActivity;
import com.example.myyiyanmengjava.R;
import com.example.myyiyanmengjava.adapter.TextViewAdapter;
import com.example.myyiyanmengjava.callback.Mainconcations;
import com.example.myyiyanmengjava.model.HomeModel;
import com.example.myyiyanmengjava.presenter.HomePresenter;

import java.util.ArrayList;
import java.util.List;

/**
 * wikipediaMap.put("modular", "zgzb");         wikipediaMap.put("secondModular", secondModular);
 * 作者：朱勇闯
 * data : 2021/4/16  11:42
 * 作用： 资讯下市场百科
 */
public class VpFragment<T> extends BaseMvpFragment<Mainconcations.MainView, HomeModel, HomePresenter<T>> implements Mainconcations.MainView<T> {

    private static final String TAG = "朱勇闯";
    private RecyclerView rv_list;
    private List tiTypeList;
    private TextViewAdapter textViewAdapter;
    private int size;
    private ArrayList<String> sizes;
    private ArrayList<String> zuos;
    private ArrayList<String> ti_ids;
    private ArrayList<String> ban1;

    @Override
    protected HomePresenter<T> createPresenter() {
        return new HomePresenter<>();

    }

    @Override
    protected void initEvent() {
        initView();
        Bundle arguments = getArguments();
        tiTypeList = arguments.getStringArrayList("TypeList");
        sizes = arguments.getStringArrayList("sizes");
        zuos = arguments.getStringArrayList("zuos");
        ti_ids = arguments.getStringArrayList("ti1");
        ban1 = arguments.getStringArrayList("ban1");
        rv_list.setLayoutManager(new LinearLayoutManager(context));
        textViewAdapter = new TextViewAdapter(tiTypeList, context, R.layout.item_titype);
        rv_list.setAdapter(textViewAdapter);
//        Log.e(TAG, "initEvent: 22222" + tiTypeList.get(0));
        textViewAdapter.setListener(new TextViewAdapter.onItemListener() {
            @Override
            public void onClick(int n) {
                String o = (String) tiTypeList.get(n);
                String size = (String) sizes.get(n);
                String zuo = (String) zuos.get(n);
                String ti_id = (String) ti_ids.get(n);
                String ban = (String) ban1.get(n);
                Toast.makeText(mActivity, "你点击了" + o, Toast.LENGTH_SHORT).show();

                Intent intent = new Intent(getContext(), HomeActivity.class);
                intent.putExtra("type", o);
                intent.putExtra("size", size);
                intent.putExtra("zuo", zuo);
                intent.putExtra("ti2", ti_id);
                intent.putExtra("ban2", ban);

                startActivity(intent);
            }
        });
    }

    @Override
    protected int createLayoutId() {
        return R.layout.fragment_titype;
    }

    @Override
    public void showList(Object t, int type) {

    }

    @Override
    public void showError(String error) {
        Log.e(TAG, "showError: " + error);
    }

    @Override
    public void showProgressbar() {

    }

    @Override
    public void hideProgressbar() {

    }

    public void initView() {
        rv_list = getView().findViewById(R.id.rv_tiType);
    }
}

